# -*- coding:utf-8 -*-
# @FileName  :t4.py
# @Time      :2021/5/18 15:14
import datetime
import io
import sys
from time import sleep
from sql_ac.sql_1 import insert_merberid
import pynput
from selenium import webdriver
from selenium.common.exceptions import ElementClickInterceptedException, NoSuchElementException
from selenium.webdriver import DesiredCapabilities
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from xlrd import open_workbook
from xlutils.copy import copy
from pynput.mouse import Controller, Button, Listener as MouseLister
sys.stdout = io.TextIOWrapper(sys.stdout.buffer,encoding='gb18030')
# chrome_options 初始化选项
sys.setrecursionlimit(1000000)
# chrome_options 初始化选项
chrome_options = webdriver.ChromeOptions()
# 设置浏览器初始 位置x,y & 宽高x,y
chrome_options.add_argument("--disable-blink-features=AutomationControlled")
chrome_options.add_argument(f'--window-position={217},{92}')
chrome_options.add_argument(f'--window-size={1222},{816}')
chrome_options.add_experimental_option("excludeSwitches", ['enable-automation'])
chrome_options.add_experimental_option("prefs", {"profile.managed_default_content_settings.images": 2})
chrome_options.add_argument('–headless')
desired_capabilities = DesiredCapabilities.CHROME  # 修改页面加载策略
desired_capabilities["pageLoadStrategy"] = "none"
driver = webdriver.Chrome(options=chrome_options)
# with open('stealth.min.js') as f:
#     js = f.read()
# driver.execute_cdp_cmd("Page.addScriptToEvaluateOnNewDocument", {
#   "source": js
# })
# driver.set_page_load_timeout(10)
driver.execute_cdp_cmd("Page.addScriptToEvaluateOnNewDocument", {
    "source": """Object.defineProperty(navigator, 'webdriver', {get: () => undefined})""",
})
wait = WebDriverWait(driver, 20)

def main():
    driver.get('https://m.dianping.com/shop/G1WuNcQxjW8WeXFk')
    phone = driver.find_element_by_xpath("//a[@class='tel']").get_attribute('href')
    # phones = driver.find_element_by_xpath("//a[@class='tel']").text
    # name = driver.find_element_by_xpath("//h1[@class='shopName']").text
    # addr = driver.find_element_by_xpath("//div[@class='address_left']/p[2]").text
    # phones = driver.find_element_by_xpath("//div[@class='aboutPhoneNum']").text
    print(phone)


if __name__ == "__main__":
    main()
